use cosmwasm_std::{HumanAddr, StdResult, Storage, Uint128};
use cosmwasm_storage::{ReadonlySingleton, Singleton};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub const CONFIG_KEY: &[u8] = b"config";

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct ConfigInfo {
    pub owner: HumanAddr,
    pub exec_bot: HumanAddr,
    pub usdt_token_address: HumanAddr,
    pub usdt_token_code_hash: String,
    pub swaper_address: HumanAddr,
    pub swaper_code_hash: String,
    pub bridge_fee: u64,
    pub min_bridge_fee: Uint128,
    pub per_tx_limit: Uint128,
    pub daily_tx_limit: Uint128,
    pub daily_exec_amount: Uint128,
    pub update_block_time: u64,
}

pub fn store_config<S: Storage>(storage: &mut S, data: &ConfigInfo) -> StdResult<()> {
    Singleton::new(storage, CONFIG_KEY).save(data)
}

pub fn read_config<S: Storage>(storage: &S) -> StdResult<ConfigInfo> {
    ReadonlySingleton::new(storage, CONFIG_KEY).load()
}
